import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.concurrent.TimeUnit;

import static java.lang.Thread.sleep;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        test06();
    }


    private static void test07() {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com");
        webDriver.switchTo().frame("");
    }
    private static void test06() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.bilibili.com/");
        sleep(2000);
        webDriver.findElement(By.cssSelector(".nav-search-input")).sendKeys("原神");
        webDriver.findElement(By.cssSelector(".nav-search-input")).sendKeys(Keys.ENTER);
//        webDriver.findElement(By.cssSelector(".nav-search-btn")).click();
        sleep(2000);
        webDriver.close();
        sleep(2000);
        webDriver.quit();
    }
    private static void test01() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com");
//        通过Css选择对应的元素
        WebElement element = webDriver.findElement(By.cssSelector("#kw"));
        element.sendKeys("原神芙宁娜");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(3000);
        WebElement webElement = webDriver.findElement(By.cssSelector("#kw"));
        webElement.clear();
        webElement.sendKeys("原神雷神");
        webDriver.findElement(By.cssSelector("#su")).click();
    }

    private static void test02() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.dm295.com/");
        WebElement element =webDriver.findElement(By.cssSelector("#hl-search-text"));
        sleep(3000);
        element.sendKeys("想要成为影之实力者");
        webDriver.findElement(By.cssSelector(".hl-search-submit")).click();
    }

    private static void test03() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.bilibili.com");
//        通过Css选择对应的元素
        WebElement element = webDriver.findElement(By.cssSelector(".nav-search-input"));
        //点击登录按钮
        webDriver.findElement(By.cssSelector("#i_cecream > div.bili-feed4 > div.bili-header.large-header > div.bili-header__bar > ul.right-entry > li:nth-child(1) > li > div.right-entry__outside.go-login-btn > div")).click();
        //输入账号
        WebElement webElement = webDriver.findElement(By.cssSelector("body > div.bili-mini-mask > div > div.bili-mini-login-right-wp > div.login-pwd-wp > form > div:nth-child(1) > input[type=text]"));
        webElement.sendKeys("2986797216");
//        while (true) {
//            webDriver.findElement(By.cssSelector("#i_cecream > div.bili-feed4 > main > div.feed2 > div > div.feed-roll-btn.smallest.translucent > button")).click();
//            sleep(3000);
//        }
    }

    private static void test04() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.bilibili.com");
//        webDriver.manage().window().fullscreen();
//        sleep(1000);
        int i = 0;
        while (i<100) {
            if (i == 1) {
                webDriver.manage().window().fullscreen();
            }
            webDriver.findElement(By.cssSelector("#i_cecream > div.bili-feed4 > main > div.feed2 > div > div.feed-roll-btn.smallest.translucent > button > span")).click();
            sleep(3000);
            i++;
        }
    }

    private static void test05() throws InterruptedException {
        WebDriver webDriver = new ChromeDriver();
        webDriver.get("https://www.baidu.com");
//        通过Css选择对应的元素
        WebElement element = webDriver.findElement(By.cssSelector("#kw"));
        element.sendKeys("原神芙宁娜");
        webDriver.findElement(By.cssSelector("#su")).click();
        sleep(6000);
        webDriver.navigate().back();
        sleep(6000);
        webDriver.navigate().refresh();
        sleep(6000);
        webDriver.navigate().forward();
        webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
    }
}


